<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>商品列表</title>
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.min.css}"/>
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>

</head>
<body>
<img src="https://www.csxbank.com/Upload/Template/yizhu/SiteConfigPhoto/Original/202008/4a90d217-c486-414e-8807-874d4fed453d.png">
<!--<img src="http://www.fwwb.org.cn/static/images/logo.jpg" style="float: right">-->
<div class="panel panel-default">
    <div class="panel-heading">秒杀商品列表</div>
    <table class="table" id="goodslist">
<!--        <tr>-->
<!--            <td>商品名称</td>-->
<!--            <td>商品图片</td>-->
<!--            <td>商品原价</td>-->
<!--            <td>秒杀价</td>-->
<!--            <td>库存数量</td>-->
<!--            <td>详情</td>-->
<!--        </tr>-->
        <tr th:each="goods,goodsStat : ${goodsList}">
            <td th:text="${goods.goodsName}"></td>
            <td><img th:src="@{${goods.goodsImg}}" width="100" height="100"/></td>
            <td th:text="${goods.goodsPrice}"></td>
            <td th:text="${goods.seckillPrice}"></td>
            <td th:text="${goods.stockCount}"></td>

            <td>
                <button th:value="${goods.id}" onclick="doApplication(this.value)">申请</button>
            </td>
            <td><button th:value="${goods.id}" onclick="toDetail(this.value)">详情</button></td>
        </tr>
    </table>
</div>
</body>
<script>

    function doApplication(goodsId) {
        console.log(goodsId)
        $.ajax({
            url: '/application/doApplication',
            type: "GET",
            data: {
                goodsId: goodsId
            },
            success: function (data) {
                if (data.code==200){
                    layer.msg(data.object);
                }else {
                    layer.msg(data.message);
                }
            }, error: function () {
                layer.msg("客户端请求出错");
            }
        });
    }

    function toDetail(goodsId) {
        $.ajax({
           url: '/application/check',
            type: "GET",
            data: {
                goodsId: goodsId
            },
            success: function (data) {
               if (data.code == 200){
                   layer.msg("申请通过");
                   window.location.href = "/goodsDetail.html?goodsId="+goodsId;
               }else {
                   layer.msg(data.message);
               }
            }, error: function () {
                layer.msg("客户端请求出错");
            }
        });
    }
</script>
</html>